import 'package:flutter/material.dart';
class TestPage extends StatefulWidget {
  TestPage({Key? key}) : super(key: key);
  @override
  _TestPageState createState() => _TestPageState();
}
class _TestPageState extends State<TestPage> {
  List<String> dataSource = <String>[];
  final TextEditingController controller = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Test Page',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Test Page'),
        ),
        body: Column(
          children: <Widget>[
            TextField(controller: controller,),
            Expanded(
              child: ListView.builder(
                  itemCount: dataSource.length,
                  itemBuilder: (BuildContext context, int index) {
                    final item = dataSource[index];
                    return Dismissible(
                      key: Key('$item$index'),
                      onDismissed: (direction) => dataSource.removeAt(index),
                      child: ListTile(title: Text(item)),
                      background: Container(color: Colors.red),
                    );
                  }),
            ),
          ],
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            setState(() {
              if (controller.text.isNotEmpty) {
                dataSource.add(controller.text);
                controller.clear();
              }
            });
          },
          child: Icon(Icons.add),
        ),
      ),
    );
  }
}
